// controllers/section.controller.js
const pool = require('../config/db');

exports.getAllSections = async (req, res) => {
  try {
    const [rows] = await pool.query('SELECT * FROM sections');
    res.json(rows);
  } catch (err) {
    res.status(500).json({ message: err.message });
  }
};

exports.createSection = async (req, res) => {
  const { name } = req.body;
  try {
    const [result] = await pool.query(
      'INSERT INTO sections (name) VALUES (?)',
      [name]
    );
    res.status(201).json({ id: result.insertId, name });
  } catch (err) {
    res.status(400).json({ message: err.message });
  }
};